package search;

import vo.Program;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.List;

public class FileHandlerImpl implements FileHandler {
    public int program2File(List<Program> programList) {
        try {
            File file = new File("spider.txt");
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter filewriter = new FileWriter(file, false);
            BufferedWriter bufferedwriter = new BufferedWriter(filewriter);

            for (int i=0; i < programList.size(); i++) {
                String str = programList.get(i).getId() + "\t" +
                        programList.get(i).getUniversity() + "\t" +
                        programList.get(i).getCountry() + "\t" +
                        programList.get(i).getProgramName() + "t" +
                        programList.get(i).getSchool() + "\t" +
                        programList.get(i).getDegree() + "\t" +
                        programList.get(i).getEmail() + "\t" +
                        programList.get(i).getPhoneNumber() + "\t" +
                        programList.get(i).getLocation() + "\t" +
                        programList.get(i).getDeadlineWithAid() + "\t" +
                        programList.get(i).getDeadlineWithoutAid() + "\t" +
                        programList.get(i).getHomepage();
                bufferedwriter.write(str);
                bufferedwriter.flush();
            }
            bufferedwriter.close();
            filewriter.close();
        }catch (Exception e){

        }
        return programList.size();
    }
}